package com.bxd.baodan.activity;

import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.view.animation.BounceInterpolator;
import android.widget.LinearLayout;

import com.bxd.baodan.App;
import com.bxd.baodan.R;
import com.umeng.analytics.MobclickAgent;

public class StartAskActivity extends BaseActivity implements View.OnClickListener {


    private LinearLayout fast_ask;
    private LinearLayout buy_ask;
    private LinearLayout service_ask;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_start_ask);
        setActionBarTitle("我要提问");
        fast_ask = (LinearLayout) findViewById(R.id.fast_ask);
        buy_ask = (LinearLayout) findViewById(R.id.buy_ask);
        service_ask = (LinearLayout) findViewById(R.id.service_ask);

        fast_ask.setOnClickListener(this);
        buy_ask.setOnClickListener(this);
        service_ask.setOnClickListener(this);


        WindowManager wm = (WindowManager) this
                .getSystemService(Context.WINDOW_SERVICE);
        int width = wm.getDefaultDisplay().getWidth();

        float we = width * 1f - getResources().getDimension(R.dimen.design_margin);


        /*
        LinearInterpolator(匀速）
AccelerateInterpolator（先慢后快）
AccelerateDecelerateInterpolator（先慢中快后慢）
DecelerateInterpolator（先快后慢）
CycleInterpolator（循环播放，速度为正弦曲线）
AnticipateInterpolator（先回撤，再匀速向前）
OvershootInterpolator（超过，拉回）
BounceInterpolator(回弹）
*/

        ObjectAnimator transAnim = ObjectAnimator.ofFloat(fast_ask, "translationX", -we / 2, 0);
        ObjectAnimator alphaAnim = ObjectAnimator.ofFloat(fast_ask, "alpha", 0, 1);
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.play(transAnim).with(alphaAnim);
        animatorSet.setDuration(800);
        animatorSet.setInterpolator(new BounceInterpolator());
        animatorSet.start();

        ObjectAnimator transAnim1 = ObjectAnimator.ofFloat(buy_ask, "translationX", -we, 0);
        ObjectAnimator alphaAnim1 = ObjectAnimator.ofFloat(buy_ask, "alpha", 0, 1);
        AnimatorSet animatorSet1 = new AnimatorSet();
        animatorSet1.play(transAnim1).with(alphaAnim1);
        animatorSet1.setDuration(800);
        animatorSet1.setStartDelay(200);
        animatorSet1.setInterpolator(new BounceInterpolator());
        animatorSet1.start();

        ObjectAnimator transAnim2 = ObjectAnimator.ofFloat(service_ask, "translationX", -we, 0);
        ObjectAnimator alphaAnim2 = ObjectAnimator.ofFloat(service_ask, "alpha", 0, 1);
        AnimatorSet animatorSet2 = new AnimatorSet();
        animatorSet2.play(transAnim2).with(alphaAnim2);
        animatorSet2.setDuration(800);
        animatorSet2.setStartDelay(400);
        animatorSet2.setInterpolator(new BounceInterpolator());
        animatorSet2.start();

    }


    @Override
    public void onClick(View v) {

        switch (v.getId()) {
            case R.id.fast_ask:

                if (loginStatus()) {
                     MobclickAgent.onEvent(App.getContext(), "v6_1_3_BW_wytw");
                    openActivity(FastQuestionActivity.class);
                }
                break;


            case R.id.buy_ask:
                if (loginStatus()) {
                    MobclickAgent.onEvent(App.getContext(), "v6_1_3_BW_wytw_xmbx");
                    openActivity(AskBuyActivity.class);
                }


                break;

            case R.id.service_ask:
                // TODO: 17/8/29  可能是弹出窗体
                if (loginStatus()) {
                    MobclickAgent.onEvent(App.getContext(), "v6_1_3_BW_wytw_ymbx");
                    openActivity(AskServiceActivity.class);
                }

                break;

        }

    }
}
